package com.kingdee.eas.scm.im.inv.client;

import java.awt.event.ActionEvent;
import java.util.Iterator;
import java.util.Set;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.dao.query.IQueryExecutor;
import com.kingdee.bos.dao.query.QueryExecutorFactory;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.jky.JkyHeperFacadeFactory;
import com.kingdee.eas.jky.helper.JKYHelper;
import com.kingdee.eas.scm.im.inv.MaterialReqBillFactory;
import com.kingdee.eas.scm.im.inv.MaterialReqBillInfo;
import com.kingdee.eas.scm.sm.pur.PurOrderFactory;
import com.kingdee.eas.scm.sm.pur.PurOrderInfo;

public class MaterialReqBillListUIPIEx extends MaterialReqBillListUI{

	private static final long serialVersionUID = 2146378728282218712L;
	public MaterialReqBillListUIPIEx() throws Exception {
		super();
		
	}
	protected boolean initDefaultFilter() {
		if (getUIContext().get("nextID") != null) {
			this.setPreferredSize(getMaximumSize());
			getUIContext().put(getMainBizOrgType(), SysContext.getSysContext().getCurrentFIUnit());
			return false;
		}else{
			return super.initDefaultFilter();
		}
		
	}
	protected IQueryExecutor getQueryExecutor(IMetaDataPK queryPK,
			EntityViewInfo viewInfo) {
		if (getUIContext().get("nextID") != null) {
			IQueryExecutor exec = null;
			FilterInfo filterInfo = new FilterInfo();
			Set setID = (Set) getUIContext().get("nextID");
			String projectID = null;
			Iterator it = setID.iterator();
			while (it.hasNext()) {
				projectID = (String) it.next();
				break;
			}
			if (projectID != null) {
				try {
					Set sets = JKYHelper.getPojectNextBillIDS(
							"T_IM_MaterialReqBill", "CFDefineProjectID", "'"
									+ projectID + "'");
					filterInfo.getFilterItems()
							.add(
									new FilterItemInfo("id", sets,
											CompareType.INCLUDE));
					viewInfo = new EntityViewInfo();
					viewInfo.setFilter(filterInfo);
					exec = QueryExecutorFactory.getRemoteInstance(queryPK);
					exec.setObjectView(viewInfo);
				} catch (Exception e) {

					e.printStackTrace();
				}
			}
			return exec;
		} else {
			return super.getQueryExecutor(queryPK, viewInfo);
		}
	}
	protected boolean isIgnoreCUFilter() {
		if (getUIContext().get("nextID") != null) {
			return true;
		} else {
			return super.isIgnoreCUFilter();
		}
	}
	public void onLoad() throws Exception {
		
		super.onLoad();
		this.btnAudit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				beforeActionPerformed(e);
				try {
					btnAudit_actionPerformed(e);
				} catch (Exception exc) {
					handUIException(exc);
				} finally {
					afterActionPerformed(e);
				}
			}
		});
		this.btnUnAudit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				beforeActionPerformed(e);
				try {
					btnUnAudit_actionPerformed(e);
				} catch (Exception exc) {
					handUIException(exc);
				} finally {
					afterActionPerformed(e);
				}
			}
		});
	}

	public void actionAudit_actionPerformed(ActionEvent arg0) throws Exception {
		
		super.actionAudit_actionPerformed(arg0);
	}
	public void actionUnAudit_actionPerformed(ActionEvent e) throws Exception {
		
		super.actionUnAudit_actionPerformed(e);
	}
	protected void btnAudit_actionPerformed(ActionEvent e) throws EASBizException {
//		try {
//			checkSelected();
//			String id=this.getSelectedKeyValue();
//			MaterialReqBillInfo perInfo =MaterialReqBillFactory.getRemoteInstance().getMaterialReqBillInfo(new ObjectUuidPK(id));
//			JkyHeperFacadeFactory.getRemoteInstance().subMaterial(perInfo);
//		} catch (BOSException e1) {
//			e1.printStackTrace();
//		}
	}
	protected void btnUnAudit_actionPerformed(ActionEvent e) throws EASBizException {
//		try {
//			String id=this.getSelectedKeyValue();
//			MaterialReqBillInfo perInfo =MaterialReqBillFactory.getRemoteInstance().getMaterialReqBillInfo(new ObjectUuidPK(id));
//			JkyHeperFacadeFactory.getRemoteInstance().backMaterial(perInfo);
//		} catch (BOSException e1) {
//			e1.printStackTrace();
//		}
	}
}